<?php

namespace App\Console\Commands\Mybank;

use App\Kuafu\Order\Model\OrderSplitModel;
use App\Kuafu\WaiMai\Model\WaiMaiOrderModel;
use Illuminate\Console\Command;
use Symfony\Component\Console\Helper\ProgressBar;

class ClearMyBankBrokerageCommand extends Command
{
    protected $signature = 'mybank:clearBrokerage';

    public function handle()
    {
        // 不要随便执行
        return ;


        for ($i = 0; $i <= 99; $i++) {
            $list = OrderSplitModel::suffix($i)
                                   ->newQuery()
                                   ->select('orderId')
                                   ->where('brokerage', '>', 0)
                                   ->orderByDesc('brokerage')
                                   ->get();

            foreach ($list as $item) {
                $item->where('orderId', $item['orderId'])
                     ->update([
                         'brokerage' => 0
                     ]);
            }

            $list = WaiMaiOrderModel::suffix($i)
                                    ->newQuery()
                                    ->select('orderId')
                                    ->where('brokerage', '>', 0)
                                    ->orderByDesc('brokerage')
                                    ->get();

            foreach ($list as $item) {
                $item->where('orderId', $item['orderId'])
                     ->update([
                         'brokerage' => 0
                     ]);
            }

            $this->info($i . '后缀的外卖+堂食数据已清楚');
        }

        $this->info('clear success');
    }

//
//$progressBar = new ProgressBar($this->getOutput(), $list->count());
//
//$list->unique()->each(
//    /**
//     * @throws GuzzleException
//     */
//    function ($item) use ($progressBar) {
//                $this->loginOrRegister($item);
//                $progressBar->advance();
//            });
//
//$progressBar->finish();

}